﻿Option Infer On

Imports System.ComponentModel
Imports System.Windows.Forms

Public Class GrafiekAreaBlok
    Inherits GrafiekAreaBase

    Public Overrides ReadOnly Property Type() As GrafiekAreaBase.GrafiekType
        Get
            Return GrafiekType.Blok
        End Get
    End Property

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        MyBase.OnPaint(e)
        If (_data Is Nothing OrElse _data.HorizontalSpan = 0) Then Return
        Dim g As Graphics = e.Graphics
        Dim verticalSpan As Decimal = _data.MaxWaarde - _data.MinWaarde
        If (verticalSpan = 0D) Then Return
        Dim einddatum As Date = _data.StartDatum.AddDays(_data.HorizontalSpan)
        Dim aantalMaanden As Integer = (einddatum.Year - _data.StartDatum.Year) * 12 + einddatum.Month - _data.StartDatum.Month
        Dim blokBreedte As Integer = Convert.ToInt32(Me.Width / aantalMaanden)
        Dim dt As HistoriekDataSet.HistoriekDataTable = _data.DataTable
        For Each item In dt
            Dim x As Integer = Convert.ToInt32(item.Datum.Subtract(_data.StartDatum).Days * Me.Width / _data.HorizontalSpan)
            Dim y As Integer = Convert.ToInt32(item.Waarde * Me.Height / verticalSpan)
            Dim color As Color = _data.GetColor(item.Naam)
            If (y >= 0) Then
                g.DrawRectangle(Pens.Gray, x, Origin - y, blokBreedte, y)
                g.FillRectangle(New SolidBrush(color), x + 1, Origin - y + 1, blokBreedte - 1, y - 1)
            Else
                g.DrawRectangle(Pens.Gray, x, Origin, blokBreedte, -y)
                g.FillRectangle(New SolidBrush(color), x + 1, Origin + 1, blokBreedte - 1, -y - 1)
            End If
        Next
    End Sub

End Class
